package org.rabbitmq.test7;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import org.rabbitmq.utils.RabbitMqUtils;

/**
 * 消费者1号
 */
public class ReceiveLogsTopic01 {

    public static final String EXCHANGE_NAME = "topic_logs";

    public static void main(String[] args) throws Exception {
        /**
         * 1.获取信道连接
         */
        Channel channel = RabbitMqUtils.getChannel();
        //2声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"topic");
        //声明队列
        String queueName = "Q1";
        channel.queueDeclare(queueName,false,false,false,null);
        //绑定队列交换机
        channel.queueBind(queueName,EXCHANGE_NAME,"*.orange.*");
        System.out.printf("Q1等待接收消息");
        //接收消息
        DeliverCallback deliverCallback = (consumerTag, message)->{
            System.out.println("01接收到"+ new String(message.getBody(), "UTF-8"));
        };
//        等待接收消息
        channel.basicConsume(queueName,true,deliverCallback,consumerTag->{});
    }
}
